package rifl.meres4.commons.ui;

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import rifl.meres4.commons.model.Software;
import rifl.meres4.commons.step.MessageListener;

/**
 * AbstractStepFrame class.
 * 
 * @author Mark Czotter
 * @author Miklos Szennai
 * 
 */
public class StepFrame extends JFrame implements MessageListener {

	private JButton nextButton;
	private JTextArea textArea;
	
	public StepFrame(String title, int posX, int posY) {
		super(title);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setLocation(posX, posY);
		this.initializeGui();
		this.setSize(400, 400);
	}

	public void initializeGui() {
		this.nextButton = new JButton("Next Step");
		this.nextButton.setEnabled(false);
		this.textArea = new JTextArea();
		this.textArea.setEditable(false);
		JScrollPane scrollPane = new JScrollPane(textArea);
		this.getContentPane().add(scrollPane, BorderLayout.CENTER);
		this.getContentPane().add(this.nextButton, BorderLayout.SOUTH);
		this.pack();
		this.setVisible(true);
	}
	
	public JButton getNextButton() {
		return nextButton;
	}
	
	public JTextArea getTextArea() {
		return textArea;
	}
	
	@Override
	public void onMessage(Software software) {
		String prevText = getTextArea().getText();
		getTextArea().setText(prevText + "\n--------\nMessage Arrived!\n--------\n");
		getNextButton().setEnabled(true);
	}

	
}
